//
//  KeHuXiangQingCaoZuoRiZhiViewController.m
//  JuBoCRM
//
//  Created by iMac on 2024/2/17.
//  Copyright © 2024 iningKe. All rights reserved.
//

#import "KeHuXiangQingCaoZuoRiZhiViewController.h"
#import "KeHuXiangQingCaoZuoTableViewCell.h"
@interface KeHuXiangQingCaoZuoRiZhiViewController ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetSource,DZNEmptyDataSetDelegate>{
    NSArray *dataSource;
}
@property (weak, nonatomic) IBOutlet TPKeyboardAvoidingTableView *mainTableView;

@end

@implementation KeHuXiangQingCaoZuoRiZhiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.customNavBar.hidden = YES;
    
    if (@available(iOS 11.0, *)) {
        self.mainTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    
    [_mainTableView registerNib:[UINib nibWithNibName:@"KeHuXiangQingCaoZuoTableViewCell" bundle:nil] forCellReuseIdentifier:@"KeHuXiangQingCaoZuoTableViewCell"];
    
    [self getInfoFromServer];
    
    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self getInfoFromServer];
    }];

    _mainTableView.mj_header = header;
}


- (void)getInfoFromServer{
    NSMutableDictionary *paraDic = [NSMutableDictionary dictionary];
    [paraDic setValue:@"2" forKey:@"types"];
    [paraDic setValue:_customerId forKey:@"actionId"];

    [[ZZPRequest getWebUtil] postNetworkRequestURLString:@"/crmActionRecord/queryRecordList" andParas:paraDic andShowHud:YES andTransferGottenData:^(id info, NSError *error) {
        if(!error){
            dataSource = [info objectForKey:@"data"];
            [_mainTableView reloadData];
        }
        [_mainTableView.mj_header endRefreshing];
    }];
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    AllModel *model = [[AllModel alloc] init];
    model.modelInfoDictionary = dataSource[indexPath.row];
    return [tableView cellHeightForIndexPath:indexPath model:model keyPath:@"model" cellClass:[KeHuXiangQingCaoZuoTableViewCell class] contentViewWidth:[self cellContentViewWith]];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    KeHuXiangQingCaoZuoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"KeHuXiangQingCaoZuoTableViewCell"];
    AllModel *model = [[AllModel alloc] init];
    model.modelInfoDictionary = dataSource[indexPath.row];
    cell.model = model;
    
    if(indexPath.row == 0){
        cell.topLineImage.hidden = YES;
//        cell.bottomLineImage.hidden = NO;
        cell.statusImage.image = LocalImagePath(@"操作日志当前");
        model.isSelect = YES;
    }else{
        cell.topLineImage.hidden = NO;
//        cell.bottomLineImage.hidden = NO;
        cell.statusImage.image = LocalImagePath(@"操作日志操作过");
        model.isSelect = NO;
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

}


-(UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView{
    return [UIImage imageNamed:@"暂无需跟进客户"];
}

- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
    
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"暂无操作日志~"attributes: @{NSFontAttributeName: [UIFont systemFontOfSize:16],NSForegroundColorAttributeName: rgba(163, 168, 185, 1)}];
    return string;
}

- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{
    return YES;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
